//
//  ShareDialogsM.m
//  ZITHER
//
//  Created by weixin on 2018/12/6.
//  Copyright © 2018 weixn. All rights reserved.
//

#import "ShareDialogsM.h"
#import <UShareUI/UShareUI.h>
#import <UMShare/UMShare.h>

@implementation ShareDialogsM

-(void)showZYShare{
    

    NSMutableArray *shareItemsArray = [[NSMutableArray alloc]init];
    NSMutableArray *functionItemsArray = [[NSMutableArray alloc]init];
    NSArray *shareItemsTitleArray = @[@"分享朋友圈",@"分享微信",@"分享QQ",@"分享QQ空间",@"分享微博"];
    NSArray *shareItemsTitle2Array = @[@"分享_朋友圈",@"分享_微信",@"分享_qq",@"分享_QQ空间",@"分享_微博"];
    NSArray *shareItemsTitle3Array = @[@"2",@"1",@"4",@"5",@"0"];

    NSArray *functionItems1Array = @[@"分享链接",@"举报",@"屏蔽用户"];
    NSArray *functionItems2Array = @[@"分享_链接",@"更多_举报",@"用户_屏蔽"];
    NSArray *functionItems3Array = @[@"1024",@"1025",@"1026"];

    
    
    for (int i = 0; i<5; i++) {
        if ([[UMSocialManager defaultManager]isInstall:i]) {
            ZYShareItem *item = [ZYShareItem itemWithTitle:shareItemsTitleArray[i]
                                                      icon:shareItemsTitle2Array[i]
                                                   handler:^{[self itemAction:shareItemsTitle3Array[i]];}];
            [shareItemsArray addObject:item];
        }
    }

    for (int i = 0; i<2; i++) {
        ZYShareItem *itemCustom1 = [ZYShareItem itemWithTitle:functionItems1Array[i]
                                                         icon:functionItems2Array[i]
                                                      handler:^{ [self itemAction:functionItems3Array[i]];
                                                      }];
        [functionItemsArray addObject:itemCustom1];
    }

    

    
    // 创建shareView
    ZYShareView *shareView = [ZYShareView shareViewWithShareItems:shareItemsArray
                                                    functionItems:functionItemsArray];
    // 弹出shareView
    [shareView show];
    
    /*
     // OR
     ZYShareView *shareView = [[ZYShareView alloc] initWithItemsArray:@[shareItemsArray, functionItemsArray]];
     [shareView show];
     */
}


#pragma mark -

- (void)itemAction:(NSString *)title
{
    NSLog(@"%@", title);
    
    [self shareWebPageToPlatformType:[title integerValue]];
    
    //    UMSocialPlatformType_QQ                 = 4,//QQ聊天页面
    //    UMSocialPlatformType_Qzone              = 5,//qq空间
    //
    //    UMSocialPlatformType_WechatSession      = 1, //微信聊天
    //    UMSocialPlatformType_WechatTimeLine     = 2,//微信朋友圈
    //    UMSocialPlatformType_Sina               = 0, //新浪
}

- (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType
{
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    //创建网页内容对象
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:self.title descr:self.content thumImage:[UIImage imageNamed:@"icon"]];
    //设置网页地址
    shareObject.webpageUrl = self.url;
    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
        }else{
            NSLog(@"response data is %@",data);
        }
    }];
}
@end
